package com.hi.hiparty.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.actionbarsherlock.app.SherlockFragment;
import com.hi.hiparty.R;
import com.hi.hiparty.util.ImageDownloader;

public class ShowPictureFragment  extends SherlockFragment implements View.OnClickListener{
	public static final String TAG = ShowPictureFragment.class.getSimpleName();
	private final ImageDownloader imageDownloader = new ImageDownloader();
	private String url;
	private Fragment preFragment;
	private String preTagStr;
	public String getUrl() {
		return url;
	}

	public ShowPictureFragment setUrl(String url) {
		this.url = url.split("!")[0];
		return this;
	}

	public Fragment getPreFragment() {
		return preFragment;
	}

	public ShowPictureFragment setPreFragment(Fragment preFragment) {
		this.preFragment = preFragment;
		return this;
	}

	public String getPreTagStr() {
		return preTagStr;
	}

	public ShowPictureFragment setPreTagStr(String preTagStr) {
		this.preTagStr = preTagStr;
		return this;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setHasOptionsMenu(false);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		final View view = inflater.inflate(R.layout.show_picture, container, false);
		ImageView contentView = (ImageView) view.findViewById(R.id.image_detail);
		imageDownloader.download(url, contentView);
		contentView.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View v) {
				getSherlockActivity().getSupportFragmentManager().popBackStack();
			}
		});
		return view;
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.image_detail:
			getSherlockActivity().getSupportFragmentManager().popBackStack();
			break;
		default:
			return;
		}
	}

}
